<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Material extends BaseModel
{
    protected $fillable = [
        'material_classify_id',
        'supplier_id',
        'name',
        'stock',
        'number'
    ];

    // 材料分类一对一
    public function MaterialClassify()
    {
        return $this->belongsTo(MaterialClassify::class);
    }

    public function recordmaterial()
    {
        return $this->hasMany(RecordMaterial::class);
    }

    // 编号修改器
    public function setNumberAttribute($value)
    {
        if (!$value) {
            $this->attributes['number'] = time();
        } else {
            $this->attributes['number'] = $value;
        }
    }
	
    public function purchaseToMaterials()
    {
        return $this->hasMany(PurchaseToMaterial::class);
    }
}
